package com.qianfeng.plateform2203.zuul.localcache;

import com.qianfeng.plateform2203.common.constants.RedisConstants;
import com.qianfeng.plateform2203.zuul.feign.CacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Map;
import java.util.Set;

@Component
public class InitApiRouting {

    @Autowired
    CacheService cacheService;

    @PostConstruct
    public void init() throws Exception {

        // 本地缓存预热
        final Set<String> keySet = cacheService.findKeyByPartten(RedisConstants.APIRouting_REDIS_PRE+"*");

        for (String key : keySet) {
            final Map<Object, Object> map = cacheService.hGetAll(key);
            APIRoutringCache.localcache.put(key,map);
        }
    }
}
